package com.rockxin.cat.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rockxin.cat.R;

import java.util.List;

/**
 * <b>类名称：    SpinnerAdapter             <br/>
 * <b>类描述：                        <br/>
 * <b>创建人：    Lans               <br/>
 * <b>创建时间：  2018/3/9 15:12     <br/>
 * <b>修改人：                        <br/>
 * <b>修改时间：                      <br/>
 * <b>修改备注：                      <br/>
 *
 * @version 1.0.0 <br/>
 */
public class SpinnerAdapter extends BaseAdapter {
    private List<String> cardNameList;

    public SpinnerAdapter(List<String> cardNameList) {
        this.cardNameList = cardNameList;
    }

    @Override
    public int getCount() {
        return cardNameList.size();
    }

    @Override
    public Object getItem(int position) {
        return cardNameList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder;
        if (convertView == null) {
            mViewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_simple_item, parent,false);
            mViewHolder.cardName = convertView.findViewById(R.id.cardName);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        mViewHolder.cardName.setText(cardNameList.get(position));
        return convertView;
    }

    //在外面先定义，ViewHolder静态类
    static class ViewHolder {

        TextView cardName;

    }
}
